import javax.swing.*;
import java.awt.*;

public class CenteredSettingsPage {
    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            JFrame frame = new JFrame("设置页面");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(400, 300);

            JPanel panel = new JPanel(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.gridx = 0;
            gbc.gridy = 0;
            gbc.anchor = GridBagConstraints.CENTER;
            gbc.insets = new Insets(5, 5, 5, 5);

            // 添加通用设置标题
            JLabel titleLabel = new JLabel("通用设置");
            panel.add(titleLabel, gbc);

            // 添加分隔线
            gbc.gridy++;
            gbc.gridwidth = 2; // 设置跨越两列

            JSeparator separator = new JSeparator(JSeparator.HORIZONTAL);
            separator.setForeground(Color.BLACK); // 设置分隔线颜色为黑色
            separator.setBackground(Color.BLACK); // 设置分隔线颜色为黑色
            separator.setVisible(true);
            Dimension dim = separator.getPreferredSize();
            dim.height = 5; // 设置分隔线高度
            separator.setPreferredSize(dim);

            panel.add(separator, gbc);
            gbc.gridwidth = 1; // 恢复默认值

            // 添加设置详情，标签在左边，按钮、文本框和复选框在右边
            gbc.gridy++;
            JLabel label1 = new JLabel("设置1:");
            panel.add(label1, gbc);

            gbc.gridx = 1;
            panel.add(new JTextField(15), gbc);

            gbc.gridy++;
            gbc.gridx = 0;
            JLabel label2 = new JLabel("设置2:");
            panel.add(label2, gbc);

            gbc.gridx = 1;
            panel.add(new JCheckBox(), gbc);

            gbc.gridy++;
            gbc.gridx = 0;
            JLabel label3 = new JLabel("设置3:");
            panel.add(label3, gbc);

            gbc.gridx = 1;
            panel.add(new JButton("按钮"), gbc);

            frame.add(panel);
            frame.setVisible(true);
        });
    }
}
